<?php
declare (strict_types=1);

namespace quick\admin\components\element;


use quick\admin\components\Component;
use quick\admin\Element;

class ElTabs extends Element
{

    public $component = "el-tabs";


    public $panes = [];


    /**
     * ElTabs constructor.
     * @param array $panes
     * @param string $type
     */
    public function __construct(array $panes = [],string $type = '')
    {
        $type && $this->type($type);
//        $this->children(Component::tabsPane());
        !empty($panes) && $this->panes($panes);
    }


    /**
     * @param array $panes
     * @return $this
     */
    public function panes(array $panes)
    {
        $this->panes = $panes;
        return $this;
    }

    /**
     * @param string $position top/right/bottom/left
     * @return $this
     */
    public function position(string $position = 'top')
    {
        $this->attribute("tab-position", $position);
        return $this;
    }

    /**
     * @param string $type card/border-card
     * @return $this
     */
    public function type(string $type)
    {
        $this->attribute("type", $type);
        return $this;

    }


    /**
     * @return $this
     */
    public function card()
    {
        return $this->type("card");
    }


    /**
     * @return $this
     */
    public function borderCard()
    {
        return $this->type("border-card");
    }


    /**
     * @return $this
     */
    public function right()
    {
        return $this->position("right");
    }


    /**
     * @return $this
     */
    public function top()
    {
        return $this->position("top");
    }

    /**
     * @return $this
     */
    public function bottom()
    {
        return $this->position("bottom");
    }

    /**
     * @return $this
     */
    public function left()
    {
        return $this->position("left");
    }


    /**
     * @param $title
     * @param string $content
     * @param string $key
     * @return $this
     */
    public function tab($title,$content = '',string $key = '')
    {
        $key = $key ?: (string)count($this->panes);
        $pane = Component::tabsPane($key,$title,$content);
        $this->panes = array_merge($this->panes,[$pane]);
        return $this;
    }

    /**
     * @return array
     */
    public function getChildrenComponents(): array
    {
        return array_merge(parent::getChildrenComponents(),$this->panes);
    }

    public function jsonSerialize(): array
    {
        $this->props('panes',$this->panes);
        return array_merge(parent::jsonSerialize(),[]); // TODO: Change the autogenerated stub
    }
}
